set more off

*** read data ***

use "reassessments", clear

merge 1:1 swis_code year using "switchers"
drop _m

duplicates drop muni_name county_name year, force
merge 1:1 muni_name county_name year using "census demographics"
drop _m

merge 1:1 muni_name county_name year using "finances clean"
drop _m

merge 1:1 muni_name county_name year using "employment"
drop _m

drop if mi(swis_code)
keep if year > 1986 & year < 2012

*** recode for interpretation ***

gen elected = 1-D
label variable elected "Elected assessor"
replace reass = reass * 100

keep if !mi(swis_code)
xtset swis_code year

#delimit;

local X1 
	lpopulation 
	lmedianincome 
	pct65plus 
	pctwhite 
	pctunemployed 
	pctrenter 
	pctagricuture
	;

#delimit cr

local X2 ltotalrevenue pctptax surpluspcp totalftequivalent

local X `X1' `X2'

foreach x in `X' {
	su `x'
	replace `x' = (`x' - r(min)) / (r(max) - r(min))
}

*** do the regressions ***

eststo clear

eststo: xi: areg reass elected i.year, a(swis_code) cl(swis_code)
su reass if e(sample)
local mymean = string(r(mean), "%20.02fc")

eststo: xi: areg reass elected i.year `X1', a(swis_code) cl(swis_code)

eststo: xi: areg reass elected i.year `X1' `X2', a(swis_code) cl(swis_code)

#delimit;

esttab
	using "table 1.tex"
	,
		replace
		cells(b(fmt(2) star) se(par))
		eqlabels(none)
		nomtitles
		collabels(none)
		gap
		keep(elected)
		label
		mlabels(none)
		nonotes
		booktabs
		width(\hsize)
		indicate("Demographic controls = lpopulation" "Fiscal controls = ltotalrevenue")
		stats(
			N
			,
				label(
					"Observations"		
				)
				fmt(%20.0fc)
		)
		;
	
#delimit cr

shell "tabler.sh" "table 1.tex" "Reassessment (average = `mymean'\%)" "Town"
